require 'yaml'
unless defined?($libdir)
  $libdir="./"
end
  [
   'fix_as_coord', # Numbers are rows
   'ex', # excel porting
   'rbook', # Table::RBook class
   'ansi',
   'string_display_methods',
   'rtable'
   ].each {|l|
     require File.join($libdir,l)
   }

# Module encapsulating the RTable api
module Table

  # open a .rts file (a RBook)
  def fopen file
   YAML.load_file file
  end
  def Table.open file
   YAML.load_file file
  end

  #####################################
  # lazy helper to make a format string
  # x => row
  # y => column
  def fstr x,y
    "#{x}:#{y}"
  end

  ##############################################
  # Helper to get the ansi format string quickly
  # table => a Table::RTable instance
  # x => row
  # y => column
  def abs_format table,x,y
    key = fstr x,y
    ansi = ""
    if table.instance_variable_get("@ansi").has_key?(key)
      ansi = table.instance_variable_get("@ansi")[key]
    end
    if table.instance_variable_get("@alias_format").find {|f| f[0]=="#{x}:#{y}"}
          cx=table.instance_variable_get("@alias_format").find {|f| f[0]=="#{x}:#{y}"}[1]
          cy=table.instance_variable_get("@alias_format").find {|f| f[0]=="#{x}:#{y}"}[2]
          ansi = table.instance_variable_get("@ansi")["#{cx}:#{cy}"]
    end
    ansi
  end
end